package io.renren.modules.manage.service.impl;

import io.renren.modules.manage.entity.ProductEntity;
import io.renren.modules.manage.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.manage.dao.SubOrderDao;
import io.renren.modules.manage.entity.SubOrderEntity;
import io.renren.modules.manage.service.SubOrderService;


@Service("subOrderService")
public class SubOrderServiceImpl extends ServiceImpl<SubOrderDao, SubOrderEntity> implements SubOrderService {
    @Autowired
    private ProductService productService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SubOrderEntity> page = this.page(
                new Query<SubOrderEntity>().getPage(params),
                new QueryWrapper<SubOrderEntity>().eq("order_id",params.get("orderId"))
        );

        page.getRecords().forEach(subOrderEntity -> {
            ProductEntity product = productService.getById(subOrderEntity.getProductId());
            subOrderEntity.setProductName(product.getName());
        });



        return new PageUtils(page);
    }

}
